#include "EWAUITrackHeaderItem.hpp"

#include "EWAColorSet.hpp"

namespace Eyer
{
    EWAUITrackHeaderItem::EWAUITrackHeaderItem(EWAPrjTrackType _trackType, EWAUILayoutParams width, EWAUILayoutParams height)
        : EWAUIWidget(width, height)
        , trackType(_trackType)
    {
        SetWidgetName("EWAUITrackHeaderItem");
    }

    EWAUITrackHeaderItem::~EWAUITrackHeaderItem()
    {

    }

    int EWAUITrackHeaderItem::SetTrackId(const EyerString & _trackId)
    {
        trackId = _trackId;
        return 0;
    }

    int EWAUITrackHeaderItem::OnDraw()
    {
        RemoveAllUIGraph();

        // 背景
        {
            EyerSmartPtr<EWAUIGraphRect> rect(new EWAUIGraphRect());
            rect->xy.Zero();
            rect->wh = wh;
            rect->background = EWAColorSet::TRACK_HEADER_BG;
            AddUIGraph(rect);
        }

        // Header title bg
        int lineWidth = 4;
        {
            EyerSmartPtr<EWAUIGraphRect> rect(new EWAUIGraphRect());
            rect->xy.Zero();
            rect->wh.x(lineWidth);
            rect->wh.y(wh.h());

            if(trackType == EWAPrjTrackType::VIDEO){
                rect->background = EWAColorSet::TRACK_HEADER_MARKLINE_VIDEO_BG;
            }
            else if(trackType == EWAPrjTrackType::AUDIO){
                rect->background = EWAColorSet::TRACK_HEADER_MARKLINE_AUDIO_BG;
            }
            AddUIGraph(rect);
        }

        int marginLeft = lineWidth + 14;
        {
            EyerSmartPtr<EWAUIGraphLine> line(new EWAUIGraphLine());
            line->xyStart.Zero();
            line->xyStart.x(marginLeft);
            line->xyStart.y(0);

            line->xyEnd.Zero();
            line->xyEnd.x(marginLeft);
            line->xyEnd.y(wh.h());

            line->linecolor = EWAColorSet::TRACK_HEADER_LINE_BG;
            AddUIGraph(line);
        }

        int textMarginLeft = marginLeft + 10;
        {
            EyerSmartPtr<EWAUIGraphText> text(new EWAUIGraphText());
            text->textcolor = EyerColor::WHITE;
            text->str = trackId;
            text->xy.x(textMarginLeft);
            text->xy.y(10);
            AddUIGraph(text);
        }

        return 0;
    }
}